//
//  LspNbWeclomeView.swift
//  LspSwiftFinayTest
//
//  Created by lsp's mac pro on 2018/5/2.
//  Copyright © 2018年 lsp's mac pro. All rights reserved.
//

import UIKit


class LspNbWeclomeView: UIView {

    @IBOutlet weak var headImgae: UIImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var headImageLayout: NSLayoutConstraint!
    class func welcomeView() -> LspNbWeclomeView {
        let nib = UINib(nibName: "LspNbWeclomeView", bundle: nil)
        let v = nib.instantiate(withOwner: nil, options: nil)[0]
        return v as! LspNbWeclomeView
    }
    
    
    override func awakeFromNib() {
        guard let urlString = LspNbNetWorkManage.shared.userModel.avatar_large else {
            return
        }
       
        headImgae.layer.masksToBounds = true
        headImgae.layer.cornerRadius = 42.5
        headImgae.sd_setImage(with: URL.init(string: urlString), placeholderImage: UIImage.init(named: "avatar_default_big"), options: SDWebImageOptions.highPriority) { (image, error, cache, url) in
            
        }
    }
    
    //移动组件到window上
    override func didMoveToWindow() {
        self.layoutIfNeeded()
        headImageLayout.constant=bounds.size.height - 200
        //withDuration 执行
        //delay 延迟速度
        //usingSpringWithDamping 弹力
        //initialSpringVelocity 初始速度
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: [], animations: {
            self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: {
                self.nameLabel.alpha=1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
        }
    }
    
    
}
